﻿using System;
using System.Collections.Generic;

namespace Microsoft.Popfly.GameCreator.Collections
{
    public class OrderedDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        List<TKey> keyList = new List<TKey>();
        List<TValue> valueList = new List<TValue>();

        public new void Add(TKey key, TValue value)
        {
            if (base.ContainsKey(key))
            {
                Microsoft.Popfly.GameCreator.GameEngine.Console.ReportError(
                    "Cannot add another item with a name of '" + key.ToString() + "' because one already exists.");
                return;
            }
            base.Add(key, value);
            keyList.Add(key);
            valueList.Add(value);
        }
        public new bool Remove(TKey key)
        {
            int indexToRemove = keyList.IndexOf(key);
            if (indexToRemove != -1)
            {
                keyList.RemoveAt(indexToRemove);
                valueList.RemoveAt(indexToRemove);
                return base.Remove(key);
            }
            return false;
        }
        public TKey getIndexedKey(int index)
        {
            return keyList[index];
        }
        public TValue getIndexedValue(int index)
        {
            return valueList[index];
        }
    }
}
